package com.mrjy.maintain.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.entity.UserScancodeInfo;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.maintain.bo.IUserScanCodeInfoBo;
import com.mrjy.maintain.dto.UserScancodeInfoDto;

@Controller
@RequestMapping("/maintain/userScancode")
public class UserScancodeController {
	
	@Resource
	private IUserScanCodeInfoBo userScanCodeInfoBo;
	
	
	/**
	 * 添加用户扫描日志
	 * @param info.userId, info.shareCode
	 * @return map
	 * @author Javin
	 */
	@RequestMapping("/insertUserScanInfo")
	@ResponseBody
	public Object insertUserScanInfo(UserScancodeInfo info){
		return userScanCodeInfoBo.txInsertUserScanInfo(info);
	}
	
	/**
	 * 分页查询扫码日志列表
	 * @param info.RecommendCode
	 * @return
	 */
	@RequestMapping("/queryPageByShareCode")
	@ResponseBody
	public Object queryPageByRecommendCode(UserScancodeInfoDto info,HttpSession session){
		UserInfo userInfo = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		Map<String, Object> map = new HashMap<String,Object>();
		if(null == userInfo){
			map.put("err_code", -1);
			map.put("err_msg", "用户信息不存在");
			return map;
		}
		return userScanCodeInfoBo.queryPageByShareCode(info ,userInfo,map);
	}
	
	/**
	 * 查询总扫码数和总扫码人数
	 * @param info.RecommendCode
	 * @return
	 */
	@RequestMapping("/queryTotalScanNum")
	@ResponseBody
	public Object queryTotalScanNum(UserScancodeInfoDto info,HttpSession session){
		UserInfo userInfo = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		return userScanCodeInfoBo.queryTotalScanNum(info,userInfo);
	}
	/**
	 * 分开查询 合作方和代理人的扫码日志在合并
	 * @param info.RecommendCode
	 * @return
	 */
	/*@RequestMapping("/queryPage")
	@ResponseBody
	public Object queryPage(UserScancodeInfoDto info,HttpSession session){
		return userScanCodeInfoBo.queryPage(info ,session);
	}*/
	
	/**
	 * 导出excel
	 * @return
	 */
	@RequestMapping("/export")
	@ResponseBody
	public Object export(UserScancodeInfoDto info,HttpServletResponse response,HttpSession session){
		return userScanCodeInfoBo.export(info,response,session);
	}

}
